import {Map,List,fromJS} from 'immutable';

export default (state = Map(), action) => {

  if (action.type === 'USER_LIST') {

    return state.merge({
      pagination : Map(action.pagination),
      userlist : List(action.userlist)
    });
  }

  if (action.type === 'USER_ADD') {
    return state.update('userlist',value=>{
      return value.unshift(action.info)
    });
  }

  if (action.type === 'USER_EDIT') {
    return state.update('userlist',value=>{
      return value.update(action.index,value=>{
        return action.info
      })
    });
  }

  if (action.type === 'USER_DELETE') {
    return state.update('userlist',value=>{
      return value.delete(action.index)
    });
  }

  return state;
};